
package ch.hearc.coursJava.GUI.j2D.tables;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

import javax.swing.JPanel;

public class JPanelTables extends JPanel
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public JPanelTables(int nbrTable,int nbrRangee, int rayonInitial)
		{
		this.nbrTable = nbrTable;
		this.nbrRangee = nbrRangee;
		this.rayonInitial = rayonInitial;

		this.deltaAnlge = 2 * (Math.PI / nbrTable);
		this.deltaRayon = 25;

		int rectWidth = 15;
		int rectHeight = 5;
		this.rectTable = new Rectangle2D.Double(-rectWidth / 2, -rectHeight / 2, rectWidth, rectHeight);
		this.cercle = new Ellipse2D.Double(-rayonInitial,-rayonInitial,rayonInitial*2, rayonInitial*2);

		}

	/*------------------------------------------------------------------*\
	|*							Methodes Protected						*|
	\*------------------------------------------------------------------*/

	@Override
	protected void paintComponent(Graphics g)
		{
		super.paintComponent(g);

		Graphics2D g2D = (Graphics2D)g;
		dessiner(g2D);
		}

	protected void dessiner(Graphics2D g2D)
		{
		g2D.translate(this.getSize().width / 2, this.getSize().height / 2);

		int rayon = rayonInitial;
		for(int i = 1; i <= nbrRangee; i++)
			{
			drawRangee(g2D,rayon);
			rayon += deltaRayon;
			}

		}



	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void drawRangee(Graphics2D g2D, int rayon)
		{
		g2D.setColor(Color.RED);
		g2D.draw(cercle);
		g2D.setColor(Color.BLUE);

		for(int i = 1; i <= this.nbrTable; i++)
			{
			g2D.translate(0, -rayon);
			g2D.draw(rectTable);
			g2D.translate(0, rayon);
			g2D.rotate(deltaAnlge);
			}
		}


	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	//Tools
	private Rectangle2D rectTable;
	private Ellipse2D cercle;
	private int nbrTable;
	private int nbrRangee;
	private double deltaAnlge;
	private double deltaRayon;

	//Input
	private int rayonInitial;

	}
